#!/bin/sh

. /usr/share/common

start() {
	echo_title "Checking sysupgrade"

	if [ "true" != "$sysupgrade_complete" ]; then
		echo_info "Mark sysupgrade complete"
		fw_setenv sysupgrade_complete true
		play /usr/share/sounds/thingino.opus
	fi
}

stop() {
	echo_title "Checking for upgrade"

	if [ -f "/tmp/upgrade.me" ]; then
		echo_warning "Running full upgrade"
		yes yes | sysupgrade -f
	elif [ -f "/tmp/update.me" ]; then
		echo_warning "Running partial upgrade"
		sysupgrade -p
	fi
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1
		;;
esac

exit 0
